<?php

/**
 * 控制器
 *
 * @author heshun
 */
class www_index extends controller {

    static public function init()
    {
        parent::init(parent::INIT_TEMPLATE | parent::INIT_SESSION);
    }

    // 显示首页
    static public function show()
    {
        dump('hello, world');
    }

    static public function register()
    {
        if (Request::isPost())
        {
            $user = Request::getPost('user', 'trim');
            $password = Request::getPost('password', 'trim');
            if (strlen($user) < 5 || strlen($password) < 5)
            {
                throw new APF_exception('无效的用户名或密码，必须大于5个字符');
            }
            $data = array('user' => $user, 'password' => $password);
            require_module('demo.user');
            $result = user::addItem($data);
            if ($result)
            {
                msg('注册成功！', '/index.php');
            }
            else
            {
                msg('注册失败！');
            }
        }

        if ( ! empty($GLOBALS['_SESSION']->user))
        {
            redirect('index.php');
        }
        self::$page->assign('welcomeMessage', '欢迎你注册！');

        self::$page->show('register');
    }

    static public function login()
    {

    }

    static public function logout()
    {

    }

    static public function showUsers()
    {
        
    }
}
?>
